#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 5e5 + 10;

int t;
string s;

map<char, int> pos; // 最后一次出现的位置
map<char, int> cnt; // 字母的数量

void clear() {
    pos.clear();
    cnt.clear();
}

bool check(string s1, string s2, string base) {
    string t = s1;
    for (int i = 0; i < s2.size(); i++) {
        s1.erase(remove(s1.begin(), s1.end(), s2[i]), s1.end());
        t += s1;
    }

    return t == base;
}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> t;

    while (t--) {
        clear();
        string s;
        cin >> s;
        int n = s.size();

        string s2;
        for (int i = n - 1; i >= 0; i--) {
            cnt[s[i]] ++;
            if (!pos[s[i]]) {
                pos[s[i]] = i;
                s2 += s[i];
            }
        }

        reverse(s2.begin(), s2.end());
        int n2 = s2.size();

        bool flag = true;

        int p = n - 1;
        for (int i = n2 - 1; i >= 1; i--) {
            if (!flag) break;
            int sublen = 0;
            map<char, int> sub;
            for (int j = i; j < n2; j++) {
                if (cnt[s2[j]] % (j + 1)) {
                    flag = false;
                    break;
                }
                sublen += cnt[s2[j]] / (j+1);
                sub[s2[j]] = cnt[s2[j]] / (j+1);
            }

            for (int j = 0; j < sublen; j++, p--) {
                if (!sub[s[p]]) {
                    flag = false;
                    break;
                }
                sub[s[p]] --;
            }

            if (!flag) break;
        }

        string s1 = s.substr(0, p + 1);

        flag = flag & check(s1, s2, s);

        if (flag) cout << s1 << ' ' << s2 << endl;
        else cout << -1 << endl;
    }
    return 0;
}
// everywherevrywhrvryhrvrhrvhv
// everywhere vrywhr vryhr vrhr vh v
// everywhere ewyrhv